﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace KhuyenMaiVang.Models
{
    public class PagingModel
    {
        public PagingModel(String controller, String action, RouteValueDictionary otherRoutes, int currentPage, int totalData)
            : this(controller, action, otherRoutes, currentPage, totalData, 10, 10)
        {

        }
        public PagingModel(String controller, String action, RouteValueDictionary otherRoutes,
                    int currentPage, int totalData, int numDataPerPage, int numPaging)
        {
            this.Controller = controller;
            this.Action = action;
            this.OtherRoutes = otherRoutes;

            this.TotalData = totalData;
            this.TotalPage = this.TotalData / numDataPerPage + 1;
            this.CurrentPage = currentPage;
            this.PageMin = Utility.Clamp(this.CurrentPage - numPaging / 2, 1, this.TotalPage);
            this.PageMax = Utility.Clamp(this.CurrentPage + numPaging / 2, 1, this.TotalPage);

            this.DataStart = Utility.Clamp((currentPage - 1) * numDataPerPage, 0, this.TotalData);
            this.DataEnd = Utility.Clamp(this.DataStart + numDataPerPage, 0, this.TotalData);
        }

        public int _PageMin;
        public int _PageMax;
        public int _TotalPage;
        public int _CurrentPage;
        public int _TotalData;
        public int _DataStart;
        public int _DataEnd;
        public String _Action;
        public String _Controller;
        public RouteValueDictionary _OtherRoutes;

        public int PageMin
        {
            get { return _PageMin; }
            set { _PageMin = value; }
        }

        public int PageMax
        {
            get { return _PageMax; }
            set { _PageMax = value; }
        }

        public int TotalPage
        {
            get { return _TotalPage; }
            set { _TotalPage = value; }
        }

        public int CurrentPage
        {
            get { return _CurrentPage; }
            set { _CurrentPage = value; }
        }

        public int TotalData
        {
            get { return _TotalData; }
            set { _TotalData = value; }
        }

        public int DataStart
        {
            get { return _DataStart; }
            set { _DataStart = value; }
        }

        public int DataEnd
        {
            get { return _DataEnd; }
            set { _DataEnd = value; }
        }


        public System.Web.Routing.RouteValueDictionary OtherRoutes
        {
            get { return _OtherRoutes; }
            set { _OtherRoutes = value; }
        }

        public string Action
        {
            get { return _Action; }
            set { _Action = value; }
        }

        public string Controller
        {
            get { return _Controller; }
            set { _Controller = value; }
        }
    }
}